home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / serien / purity / nr.20 / reset / reset_wb2.0.p < prev    next >
Text File  |  1995-04-22  |  4KB  |  170 lines

  1. Program Reset;
  2.  
  3. {    Reset V1.0
  4.      © 1993 by Andreas Tetzl.
  5.      Dieses Programm ist Freeware.
  6.  
  7.  Die Datei TrapHandler.o muß zum Objektcode dazugelinkt werden. }
  8.  
  9.  
  10. { Das Programm funktionierte auf einem CDTV mit Kickstart 2.0 nicht richtig.
  11.   Diese Datei wurde an OS2.0 angepasst.
  12. }
  13.  
  14. {$I "Include:Intuition/Intuition.i"}
  15. {$I "Include:Graphics/Graphics.i"}
  16. {$I "Include:Graphics/Pens.i"}
  17. {$I "Include:Exec/ExecBase.i"}
  18. {$I "Include:Exec/Interrupts.i"}
  19. {$I "Include:Exec/Ports.i"}
  20. {$I "Include:Exec/Tasks.i"}
  21. {$I "Include:Exec/Memory.i"}
  22. {$I "Include:Exec/Interrupts.i"}
  23. {$I "Include:Exec/Devices.i"}
  24. {$I "Include:Utils/IOUtils.i"}
  25. {$I "Include:Devices/KeyBoard.i"}
  26. {$I "Include:Exec/IO.i"}
  27. {$I "Include:Libraries/DOS.i"}
  28. {$I "Include:Utils/StringLib.i"}
  29.  
  30. Const  StdIn = NIL;       { Damit auf der WB kein Window geöffnet wird }
  31.       StdOut = StdIn;
  32.  
  33. Type MyData = Record
  34.       MyTask : TaskPtr;
  35.       MySignal : Integer;
  36.      end;
  37.      
  38.  
  39. VAR  KeyIO             : IOStdReqPtr;
  40.      KeyMP             : MsgPortPtr;
  41.      KeyHandler        : InterruptPtr;
  42.      MyDataStuff       : MyData;
  43.      MySignal, OpenDev : Integer;
  44.      SysBase           : ExecBasePtr;
  45.      
  46. Procedure ColdReboot;
  47. Begin
  48. {$A
  49.     move.l    $4,a6
  50.     jmp        -726(a6)        ; ColdReboot Exec.lib V37+
  51. }
  52. end;
  53.  
  54. Procedure Reset;
  55. Const
  56.  
  57.    Topaz : TextAttr = ("topaz.font",8,FS_NORMAL,FPB_ROMFONT);
  58.         
  59.    WarmGadgetText : IntuiText = (1,0,JAM1,3,3,@Topaz,"WarmStart",NIL);
  60.    KaltGadgetText : IntuiText = (1,0,JAM1,3,3,@Topaz,"KaltStart",NIL);
  61.  
  62.    ResetText : IntuiText=(1,0,JAM1,16,10,@Topaz,"Reset V1.0 © 1993 by Andreas Tetzl",NIL);
  63.  
  64. VAR  Win : WindowPtr;
  65.      RP : RastPortPtr;
  66.     Msg, MsgCpy : IntuiMessagePtr;
  67.     Time, i : Short;
  68.     Gad : GadgetPtr;
  69.     Str, Zeit : String;
  70.  
  71. Begin
  72.   Str:=AllocString(20);
  73.   Win:=BuildSysRequest(NIL,adr(ResetText),adr(WarmGadgetText),adr(KaltGadgetText),GADGETUP_f,200,40);
  74.   SetWindowTitles(Win,"Reset V1.0 by Andreas Tetzl",NIL);
  75.   
  76.   Time:=10;
  77.   Repeat
  78.    i:=IntToStr(Zeit,Time);
  79.    StrCpy(Str,"Reset in ");
  80.    StrCat(Str,Zeit);
  81.    StrCat(Str," Sekunden");
  82.    SetWindowTitles(Win,Str,NIL);
  83.    For i:=1 to 5 do
  84.     Begin
  85.      Delay(10);
  86.      Msg:=IntuiMessagePtr(GetMsg(Win^.UserPort));
  87.      If Msg<>NIL then
  88.       Begin
  89.        Gad:=Msg^.Iaddress;
  90.        If Gad^.GadgetID=1 then   { Warmstart }
  91.         ColdReboot;    { Reset }
  92.        If Gad^.GadgetID=0 then   { Kaltstart }
  93.         Begin
  94.          Forbid;                     { Damit sich Viren nicht neu installieren können }
  95.          SysBase^.ColdCapture:=NIL;  { Resetvektoren löschen }
  96.          SysBase^.CoolCapture:=NIL;
  97.          SysBase^.WarmCapture:=NIL;
  98.          SysBase^.KickMemPtr:=NIL;
  99.          SysBase^.KickTagPtr:=NIL;
  100.          SysBase^.KickCheckSum:=NIL;
  101.          ColdReboot;         { Reset }
  102.         end;         
  103.       end;
  104.     end;
  105.    Dec(Time);
  106.   Until Time=0;   { Nach Zehn Sekunden wird automatisch ein Reset ausgeführt }
  107. end;
  108.  
  109. Procedure Meldung;
  110. VAR  Con : FileHandle;
  111.     z : Integer;
  112. Begin
  113.   Con:=DOSOpen("con:128/100/320/50/Reset",MODE_NEWFILE);
  114.   If Con=NIL then Return;
  115.   z:=DOSWrite(Con,"Reset V1.0 von Andreas Tetzl installiert\n",41);
  116.   Delay(100);
  117.   DOSClose(Con);
  118. end;
  119.  
  120. Procedure ResetHandler;
  121. External;
  122.  
  123. Function WaitForSignal(MySignal : Integer) : Short;
  124. Begin
  125.   WaitForSignal:=Wait(MySignal);
  126. end;
  127.  
  128. Procedure CleanExit;
  129. Begin
  130.   If OpenDev=0 then CloseDevice(KeyIO);
  131.   If KeyIO<>NIL then DeleteStdIO(KeyIO);
  132.   If KeyMP<>NIL then DeletePort(KeyMP);
  133.   If MySignal<>-1 then FreeSignal(MySignal);
  134.   DisplayBeep(NIL);
  135. end;
  136.  
  137. Begin
  138.   {$A    move.l    $4,_SysBase   }
  139.   OpenDev:=1;
  140.  
  141.   New(KeyHandler);
  142.   MySignal:=AllocSignal(-1);
  143.   If MySignal=-1 then CleanExit;
  144.  
  145.   MyDataStuff.MyTask:=FindTask(NIL);
  146.   MyDataStuff.MySignal:=1 SHL MySignal;
  147.   KeyMP:=CreatePort(NIL,0);
  148.   If KeyMP=NIL then CleanExit;
  149.  
  150.   KeyIO:=CreateStdIO(KeyMP);
  151.   If KeyIO=NIL then CleanExit;
  152.   
  153.   OpenDev:=OpenDevice("keyboard.device",0,KeyIO,0);
  154.   If OpenDev<>0 then CleanExit;
  155.   
  156.  
  157.   KeyHandler^.is_Code:=adr(ResetHandler);
  158.   KeyHandler^.is_Data:=adr(MyDataStuff);
  159.   Keyhandler^.is_Node.ln_Pri:=16;
  160.   KeyHandler^.is_Node.ln_name:="Reset";
  161.   KeyIO^.io_Data:=KeyHandler;
  162.   KeyIO^.io_Command:=KBD_ADDRESETHANDLER;            { ResetHandler installieren }
  163.   If DoIO(KeyIO)<>0 then CleanExit;
  164.   Meldung;
  165.   If WaitForSignal(MyDataStuff.MySignal)=0 then      { auf Reset warten }
  166.    Begin
  167.     Reset;
  168.    end;
  169. end.
  170.